using System;
using UnityEngine;
using UnityEngine.SceneManagement;
using Voodoo.Sauce.Debugger;
using Voodoo.Sauce.Tools.AccessButton;

public class CheatsManager : MonoBehaviour
{
	public GameObject[] CheatsPrefabs;

	private static CheatsManager _instance;

	private bool _initialized;

	public static CheatsManager Instance
	{
		get
		{
			if (!_instance)
			{
				_instance = UnityEngine.Object.FindObjectOfType<CheatsManager>();
			}
			return _instance;
		}
	}

	private void Awake()
	{
		_instance = this;
		HidePanel.HideChangeState = (HidePanel.OnHideChangeState)Delegate.Combine(HidePanel.HideChangeState, new HidePanel.OnHideChangeState(OnDebugButtonClicked));
	}

	private void OnDestroy()
	{
		HidePanel.HideChangeState = (HidePanel.OnHideChangeState)Delegate.Remove(HidePanel.HideChangeState, new HidePanel.OnHideChangeState(OnDebugButtonClicked));
	}

	private void OnDebugButtonClicked(bool appear)
	{
		if (_initialized)
		{
			return;
		}
		DebuggerCanvas debuggerCanvas = UnityEngine.Object.FindObjectOfType<DebuggerCanvas>();
		if (!debuggerCanvas)
		{
			return;
		}
		DebugAccessButton componentInChildren = debuggerCanvas.transform.GetComponentInChildren<DebugAccessButton>(includeInactive: true);
		if ((bool)componentInChildren)
		{
			_initialized = true;
			HidePanel.HideChangeState = (HidePanel.OnHideChangeState)Delegate.Remove(HidePanel.HideChangeState, new HidePanel.OnHideChangeState(OnDebugButtonClicked));
			Transform parent = componentInChildren.transform.parent;
			for (int i = 0; i < CheatsPrefabs.Length; i++)
			{
				UnityEngine.Object.Instantiate(CheatsPrefabs[i], parent);
			}
		}
	}

	public int GetCurrentLevel()
	{
		return NintendoPlayerPrefs.GetInt("Level", 0);
	}

	public void SetLevel(int val)
	{
		NintendoPlayerPrefs.SetInt("Level", val);
	}

	public void AddLevel(int amount)
	{
		int level = Mathf.Max(GetCurrentLevel() + amount, 0);
		SetLevel(level);
		UnityEngine.Object.FindObjectOfType<Shop>().ResetAllSells();
	}

	public int GetCurrentCoins()
	{
		return (int)NintendoPlayerPrefs.GetFloat("Money", 0f);
	}

	public void SetCoins(int val)
	{
		NintendoPlayerPrefs.SetFloat("Money", val);
	}

	public void AddCoins(int amount)
	{
		int coins = Mathf.Max(GetCurrentCoins() + amount, 0);
		SetCoins(coins);
	}

	public int GetCurrentGems()
	{
		return NintendoPlayerPrefs.GetInt("Gems", 0);
	}

	public void SetGems(int val)
	{
		NintendoPlayerPrefs.SetInt("Gems", val);
	}

	public void AddGems(int amount)
	{
		int gems = Mathf.Max(GetCurrentGems() + amount, 0);
		SetGems(gems);
	}

	public void Reload()
	{
		SceneManager.LoadScene("GamePlay");
	}
}
